package com.cheung.leetcode.greedy;

import org.junit.jupiter.api.Test;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.greedy
 * @Author :  cheungming
 * @CreateTime : 2024-06-06 09:04:28
 * @Description : 跳跃数组
 * @Version : 1.0
 */
public class Code55Test {

    public boolean canJump(int[] nums) {
        if (nums.length == 1) {
            return true;
        }
        int cover = 0;
        for (int i = 0; i <= cover; i++) {
            cover = Math.max(cover, i + nums[i]);
            if (cover >= nums.length - 1) {
                return true;
            }
        }

        return false;
    }


    @Test
    public void test1() {
        int[] nums = {2, 3, 1, 1, 4};
        assert canJump(nums);
    }

    @Test
    public void test2() {
        int[] nums = {3, 2, 1, 0, 4};
        assert !canJump(nums);
    }
}
